from redis import StrictRedis
redis = StrictRedis(host='localhost',port=6379,db=0,password=None)
import pickle


# for cut in a:
#     redis.rpush("list",cut)
#
# print(redis.llen('list'))
#
# len = redis.llen('list')
# ans = []
# for i in range(len):
#     ans.append(int(redis.lindex("list",i)))
# print(ans)
# print(redis.llen("disk")) ##清空redis
for elem in redis.keys():
    redis.delete(elem)

def calculat(disk, startnum):
    disk.sort()
    print(disk)
    start = 0
    for i in range(10):
        if disk[i] > startnum:
            start = i
            break
    i = start - 1
    j = start
    ans = []
    while len(ans) < 10:
        if startnum - disk[i] < disk[j] - startnum:  # 左边小 往左
            ans.append(disk[i])
            startnum = disk[i]
            i -= 1
        else:
            ans.append(disk[j])
            startnum = disk[j]
            j += 1
        if i == -1:
            ans += disk[j:]
            break
        if j == 10:
            ans += disk[:i + 1][::-1]
            break
    return ans

import random

disk = [random.randint(0, int(200)) for _ in range(10)]

# print(disk)
# print(calculat(disk, 100))
# x = 1
# print("hello", x, x+x)

# a = [1,2,3,4,5]
# redis.set("ans", pickle.dumps(a))
#
# b = pickle.loads(redis.get("ans"))
# print(b)
# print(b[:0])

class progress(object):
    def __init__(self, id, a, b, c, need_time):
        self.id = id
        self.status = "W"
        self.a = a
        self.b = b
        self.c = c
        self.need_time = need_time
        self.get_time = 0

prolist = []
for i in range(5):
    pro = progress(i, random.randint(0,5), random.randint(0,5), random.randint(0,5), random.randint(1,5))
    prolist.append(pro)

prolist.pop(0)
print(prolist[0].id)